var TestMgtService = (function () {

	var categoryServiceBase = "http://173.39.25.67:8080/edu/services/rest/categorymgt";
	var testServiceBase = "http://173.39.25.67:8080/edu/services/rest/testmgt";
	var jsonContentType = "application/json";

	getTestCategories = function (callback) {
		alert("Service Method Called");
		$.getJSON(categoryServiceBase + "/categories", function (data) {
			callback(data);
		});
		/*$.getJSON("../../modules/course/dummy/categories.json", function (data) {
			callback(data);
		});*/
	};

	getAllTests = function (callback) {
		$.getJSON("../test/sample/basictestdetails.json", function (data) {
			callback(data);
		});
	};


	getTestsInCategory = function (categoryName, callback) {
		$.getJSON("../test/sample/testsingivencategory.json", function (data) {
			callback(data);
		});
	};

	subscribeToTest = function (testCode) {

	};

	getSubscribedTests = function (callback) {
		$.getJSON("../test/sample/subscribedtests.json", function (data) {
			callback(data);
		});
	};

	getTestDetails = function (testCode, callback) {
		$.getJSON("../test/sample/testdataold.json", function (data) {
			callback(data);
		});
	};

	addTest = function (test, callback) {
		$.ajax({
			type: "POST",
			url: testServiceBase + "/tests",
			headers: {
				'Accept': 'application/json',
				'Content-Type': 'application/json'
			},
			data: JSON.stringify(test),
			contentType: jsonContentType,
			dataType: "json",
			processdata: true,
			success: function (json) {
				alert(json);
				callback(json);
			}
		});
	}

	addTestQuestions = function (testId, questions, callback) {
		$.ajax({
			type: "POST",
			url: testServiceBase + "/tests/" + testId + "/questionsList",
			headers: {
				'Accept': 'application/json',
				'Content-Type': 'application/json'
			},
			data: JSON.stringify(questions),
			contentType: jsonContentType,
			dataType: "json",
			processdata: true,
			success: function (json) {
				alert(json);
				callback(json);
			}
		});
	}

	return {
		getTestCategories: getTestCategories,
		getAllTests: getAllTests,
		getTestsInCategory: getTestsInCategory,
		getSubscribedTests: getSubscribedTests,
		getTestDetails: getTestDetails,
		addTest: addTest,
		addTestQuestions: addTestQuestions
	};

})();